package com.library.uiframework.fragment.ptr;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.library.uiframework.R;
import com.library.uiframework.fragment.StateViewFragment;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrFrameLayout;

/**
 * 在此写用途
 *
 * @version V1.0 <描述当前版本功能>
 * @FileName: com.yxwframework.view.fragment.PtrStateViewFrament.java
 * @author: zhiwei
 * @date: 2016-04-24 21:48
 */
public abstract class PtrStateViewFrament extends StateViewFragment implements PtrViewHelper.OnPtrHandlerListener{
    private static final String TAG = "PtrStateViewFrament";

    protected PtrClassicFrameLayout mPtrFrameLayout;
    private PtrViewHelper mPtrViewHelper;

    @Override
    protected final View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mPtrFrameLayout = (PtrClassicFrameLayout)inflater.inflate(getPtrContentLayout(), container, false);
        View ptrContentView = onCreatePrtContentView(inflater, mPtrFrameLayout, savedInstanceState);
        mPtrViewHelper = new PtrViewHelper(mPtrFrameLayout, this);
        return mPtrFrameLayout;
    }

    protected int getPtrContentLayout(){
        return R.layout.common_frament_ptr;
    }

    @Override
    protected final void onRetryRequested() {
        onRefreshBegin(mPtrFrameLayout);
    }

    public final PtrFrameLayout getPtrFrameLayout(){
        return mPtrFrameLayout;
    }

    ///////////////////////////////////////////////////////////////////////////
    // 子类集成
    ///////////////////////////////////////////////////////////////////////////

    /**
     * 加载完成转台回执
     */
    protected void loadFinish(){
        mPtrFrameLayout.refreshComplete();
    }



    /**
     * 获取进行下拉刷新，上拉加载更多的的显示view
     * 可以在此对 PtrFrameLayout 进行相关的设置
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    protected abstract View onCreatePrtContentView(LayoutInflater inflater, PtrFrameLayout container, Bundle savedInstanceState);
}
